package page.sample.administratorpackage;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.CompoundPropertyModel;

import page.sample.AuthorizationPage;
import dao.impl.GoodsDao;
import entity.Administrator;
import entity.Goods;

public class AddGoodsPage extends WebPage {

	public AddGoodsPage(final Administrator administrator)
	{
		
		final GoodsDao goodsDao = new GoodsDao(app.MyFirstWebApplication.DATA_XML_FOLDER);
		
		final Goods goods = new Goods();
		
		Form<Goods> form = new Form("form", new CompoundPropertyModel<Goods>(goods));
		
		form.add(new TextField<String>("name"));
		form.add(new TextField<Integer>("price"));
		
		
		
		form.add(new SubmitLink("save") {

			@Override
			public void onSubmit() {
				super.onSubmit();
				
				goodsDao.saveNew(goods);
				setResponsePage(new AdministratorPage(administrator));
				}
			});

		form.add(new Link("cancel") {

			public void onClick() {
				setResponsePage(new AdministratorPage(administrator));
			}

		});
		
		add(new Link("showUsers")
		{

			@Override
			public void onClick() {
				setResponsePage(new ShowUsers(administrator));
				
			}
			
		});
		
		add(new Link("showGoods")
		{

			@Override
			public void onClick() {
				setResponsePage(new ShowGoodsPage(administrator));
				
			}
			
		});
		
		add(new Link("addGoods")
		{

			@Override
			public void onClick() {
				setResponsePage(new AddGoodsPage(administrator));
				
			}
			
		});
		
		add(new Link("showBlackList")
		{

			@Override
			public void onClick() {
				setResponsePage(new BlackListPage(administrator));
			}
			
		});
		
		add(new Link("exit")
		{

			@Override
			public void onClick() {
				setResponsePage(new AuthorizationPage());
				
			}
			
		});
		
		add(form);
	}
}
